package com.ruoyi.modules.appController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.modules.domain.NumRecord;
import com.ruoyi.modules.service.INumRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * 次数记录Controller
 *
 * @author ruoyi
 * @date 2022-02-03
 */
@Api(tags = "app - 次数记录")
@RestController
@RequestMapping("/app/numRecord")
public class AppNumRecordController extends BaseController {
    @Autowired
    private INumRecordService numRecordService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询次数记录列表
     */
    @ApiOperation(value="次数记录列表", notes="次数记录列表")
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest req, NumRecord numRecord) {

        Long agentUserId = tokenService.getUserId(req);

        startPage();
        List<NumRecord> list = numRecordService.list(new LambdaQueryWrapper<NumRecord>()
            .eq(NumRecord::getAgentUserId, agentUserId)
            .eq(numRecord.getPayType() != null, NumRecord::getPayType, numRecord.getPayType())
            .orderByDesc(NumRecord::getCreateTime)
        );
        return getDataTable(list);
    }

}
